package Logic.EventSample.Guild;

import FrameWork.Model.Player;
import Logic.EventSample.Goods.Gain.GainGoodTrigger;
import Logic.EventSample.Goods.Gain.GainSource;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//公会升级事件
@Component
public class GuildUpgradeHandler implements GuildEventHandler {

    private Logger logger = Logger.getLogger(getClass());

    @Autowired
    private GainGoodTrigger gainGoodTrigger;

    //公会升级会根据玩家在公会贡献度不同发放不同的奖励
    @Override
    public void onGuildStateChange(Player player,GuildEventType eventType) {
        if (eventType == GuildEventType.UPGRADE){
            logger.debug("触发公会升级事件");
            int contribute = getContribute(player);
            int rewardGoodId = getRewardGoodId(contribute);
            gainGoodTrigger.fire(player,rewardGoodId,1,GainSource.GUILD);
        }
    }

    //获取用户的贡献
    private int getContribute(Player player){
        //example
        return 100;
    }

    //根据不同贡献获取不同的奖励
    private int getRewardGoodId(int contribute){
        if (contribute>500){
            return 5;
        }
        else if (contribute>200){
            return 2;
        }
        else{
            return 1;
        }
    }

}
